using System;
using System.Collections;
using System.Xml.Serialization;

/*
  <section type="text"> <!-- one of the three predefined sections that differ by importance -->
			<term-frequency>3</term-frequency> <!--term frequency in this section -->
			<sentence>
				<number>1</number> <!-- in the sentence number 1 this term comes at third place -->
				<place>3</place>
				<next-id/> <!-- this is a last term in the sentence -->
			</sentence>
			<sentence>
				<number>2</number> <!-- in the sentence number 2 this term comes at first place -->
				<place>1</place>
				<connecting-word/>
				<next-id>3</next-id>  <!-- the next term in this sentence is 3 -->
			</sentence>
			<sentence>
				<number>4</number>
				<place>6</place>
				<connecting-word>on</connecting-word>
				<next-id>2</next-id>
			</sentence>
	</section>
*/
namespace TextParsing.GraphStructure
{
	public class Section
	{
		public enum SectionType { 
			[XmlEnum("link")]Link,
			[XmlEnum("text")]Text,
			[XmlEnum("title")]Title,
			[XmlEnum("meta-keyword")]MetaKeyword,
			[XmlEnum("meta-description")]MetaDescription,
      [XmlEnum("heading")]Heading,
			[XmlEnum("caption")]Caption };

		private SectionType m_sectionType;
		private long m_termFrequency;
		private ArrayList m_sentences;

		public Section() { m_sentences = new ArrayList(); }

		[XmlAttribute("type")]
		public SectionType Type
		{
			get { return m_sectionType; }
			set { m_sectionType = value; }
		}

		[XmlElement("term-frequency")]
		public long TermFrequency
		{
			get { m_termFrequency = m_sentences.Count ; return m_termFrequency; }
			set { m_termFrequency = value; }
		}

		[XmlArrayItem("sentence",typeof(Sentence),IsNullable = false)]
		[XmlArray]
		public IList Sentences
		{
			get { return m_sentences; }
		}

		/// <summary>
		/// Get the sentence with specified number and place
		/// </summary>
		/// <param name="number">sentence number for given term</param>
		/// <param name="place">the term place in the sentence</param>
		/// <returns></returns>
		public Sentence GetSentence(int number,int place)
		{
			foreach(Sentence sentence in m_sentences)
			{
				if (sentence.Place == place && sentence.Number == number) return sentence;
			}

				return null;
		}

		/// <summary>
		/// Create new instance of the Section class
		/// </summary>
		/// <returns></returns>
		public static Section CreateNewSection() { return new Section(); }
	}
}
